import { reqGetCategory, reqBannerList, reqFresh, reqRecommend, reqTrademark, reqGoods, reqNew } from '@/api'
const actions = {
    //获取商品一级分类列表
    async getCategoryList({ commit }) {
        let result = await reqGetCategory()
        commit('GETCATEGORYLIST', result.result)
    },
    //获取轮播图数据
    async getBannerList({ commit }) {
        let result = await reqBannerList()
        commit('GETBANNERLIST', result.result)
    },
    //获取新鲜好物数据
    async getFreshList({ commit }) {
        let result = await reqFresh()
        commit('GETFRESHLIST', result.result)
    },
    //获取人气推荐数据
    async getRecommend({ commit }) {
        let result = await reqRecommend()
        commit('GETRECOMMEND', result.result)
    },
    //获取热门品牌数据
    async getTrademark({ commit }) {
        let result = await reqTrademark()
        commit('GETTRADEMARK', result.result)
    },
    //获取产品列表
    async getGoodsList({ commit }) {
        let result = await reqGoods()
        commit('GETGOODSLIST', result.result)
    },
    //获取最新专题
    async getNew({ commit }) {
        let result = await reqNew()
        commit('GETNEW', result.result)
    }

}
const mutations = {
    GETCATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETRECOMMEND(state, recommend) {
        state.recommend = recommend || []
    },
    GETFRESHLIST(state, fresh) {
        state.fresh = fresh || []
    },
    GETTRADEMARK(state, trademark) {
        state.trademark = trademark || []
    },
    GETGOODSLIST(state, goodsList) {
        state.goodsList = goodsList || []
    },
    GETNEW(state, newList) {
        state.newList = newList
    }
}
const state = {
    categoryList: [],
    bannerList: [],
    recommend: [],
    fresh: [],
    trademark: [],
    goodsList: [],
    newList: []
}
const getter = {
}
export default {
    actions,
    mutations,
    state,
    getter,
}